package com.wx.business.weixin;

import java.util.Map;

import com.wx.business.weixin.common.Configure;
import com.wx.business.weixin.common.HttpsRequestUtil;
import com.wx.business.weixin.common.XMLParser;
import com.wx.business.weixin.protocol.OrderPayReqDataH5;

public class WXUtil {

	
	
	public static String orderH5Pay( String body, String detail, String attach, String out_trade_no,
			int totalFee, String spbill_create_ip,  String trade_type, String openId) throws Exception {
		OrderPayReqDataH5 orderPayReqData = new OrderPayReqDataH5( body, detail, attach, out_trade_no, totalFee,
				spbill_create_ip, trade_type,openId);
		StringBuffer buffer = HttpsRequestUtil.httpsRequest(Configure.ORDER_API, "POST", orderPayReqData);
		Map map = XMLParser.getMapFromXML(buffer.toString());
		String return_code = (String) map.get("return_code");
		if (return_code.equals("SUCCESS")) {
			String result_code = (String) map.get("result_code");
			if (result_code.equals("SUCCESS")) {
				return (String) map.get("prepay_id");
			}
		}
		return null;
	}
	
	
	
}
